package com.link2room.rodimus.nmsrunner;

import com.aliyun.mns.model.Message;
import com.link2room.common.mns.Worker;
import com.link2room.common.util.JacksonUtil;
import com.link2room.rodimus.dto.param.base.GroupBuyingAutoRefundParamDto;
import com.link2room.rodimus.facade.IGroupBuyingManagerFacadeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by LN on 2017/12/10
 */
@Component("groupbuyingTeamAutoRefundWorker")
public class GroupbuyingTeamAutoRefundWorker implements Worker {

    @Resource
    private IGroupBuyingManagerFacadeService groupBuyingManagerFacadeService;
    @Override
    public boolean exec(Message message) throws Exception {
        String msg = message.getMessageBody();

        if(message.getDequeueCount() <= 3){
            boolean flag = true;
            GroupBuyingAutoRefundParamDto paramDto = JacksonUtil.jsonToBean(msg,GroupBuyingAutoRefundParamDto.class);
            try {
                groupBuyingManagerFacadeService.autoRefund(paramDto);
            }catch (Exception e){
                flag = false;
                throw e;
            }finally {
                return flag;
            }
        }
        return true;
    }
}
